﻿using Contract.Infrastructure.Repository;
using Contract.WebApi.Application.Commands;
using MediatR;

namespace Contract.WebApi.Application.CommandHandler
{
    public class UpdCYContractCommandHandler : IRequestHandler<UpdCYContractCommands, int>
    {
        private readonly IRepository<Domain.Contract> _repository;

        public UpdCYContractCommandHandler(IRepository<Domain.Contract> repository)
        {
            _repository = repository;
        }

        public async Task<int> Handle(UpdCYContractCommands request, CancellationToken cancellationToken)
        {
            var info = await _repository.GetAsync(request.ContractId);
            info.ContractTitle = request.ContractTitle;
            info.ShipperEnterprise = request.ShipperEnterprise;
            info.ShipperPrincipal = request.ShipperPrincipal;
            info.Route = request.Route;
            info.TonTransport = request.TonTransport;
            info.Tonnage = request.Tonnage;
            info.CharterAmount = request.CharterAmount;
            info.Responsible = request.Responsible;
            info.SigningDate = request.SigningDate;
            info.ContractAmount = request.ContractAmount;
            info.ContractObject = request.ContractObject;
            info.MainClause = request.MainClause;
            info.ContractText = request.ContractText;
            info.AuditState = request.AuditState;
            info.FreightStatus = request.FreightStatus;
            info.Abnormity = request.Abnormity;
            info.UpdateDate = DateTime.Now;
            var ind = await _repository.UpdateAsync(info);
            return ind;
        }
    }
}
